package visiopuce.graph;

import java.awt.Color;
import java.io.IOException;
import java.net.URL;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wb.swt.SWTResourceManager;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.XYItemEntity;

import visiopuce.objets.Alteration;
import visiopuce.service.AlterationServiceImpl;
import visiopuce.service.PersonneServiceImpl;
import visiopuce.service.ReferentielServiceImpl;
import visiopuce.ui.DossierEditorInput;
import visiopuce.ui.view.DossierEditor;

public class GraphCytog implements ChartMouseListener {

	private RegionGraphique regionGraphique;
	public ConfigurationPanel confPanel;
	private MyChartPanel frame;
	private int zoomValue;
	private Long defaultLowerBoundX;
	private Long defaultUpperBoundX;
	private double minBoundY;
	private double maxBoundY;
	// private Panel p;
	private ChartScrollBar hScrollBar;
	private ChartScrollBar vScrollBar;
	public Button btnZoomPlus;
	public Button btnZoomMoins;
	public static int region;
	public static int estPatient;
	// private Shell tooltipframe;
	private Button btnValidation;
	private Alteration alteration;
	private Group grpGraphique;
	// private JFreeChart overviewChart;
	private JFreeChart jFreeChart;
	public JFreeChart getjFreeChart() {
		return jFreeChart;
	}

	public void setjFreeChart(JFreeChart jFreeChart) {
		this.jFreeChart = jFreeChart;
	}

	private Composite cGraph;
	private Button btnLegende;
	private Button btnCNPc;
	// private Label tool;
	private long fin;
	private long debut;
	private ToolTipsDialog ttd;
	private int seuil = 400000;
	// public static URL codeBase;
	// public static String bandes;
	// public static String cnvChevauchants = null;
	// public static String famille;
	// public static String autrePucePatient;
	// public static String fragile;
	// public static String redon;
	// public static String cnpc;
	// public static String clone32k;
	// public static String clone4k;
	// public static String cnpLyonGain;
	// public static String cnpLyonPerte;
	// public static String cnpLyonTriplication;
	//
	// public static String cnpOuestGain;
	// public static String cnpOuestPerte;
	// public static String cnpOuestTriplication;
	//
	// // public static String clone4x44kagilent;
	// public static String clonetilepath;
	// // public static String dgv;
	// public static String imprinting;
	// public static String groupe;
	// public static String microrem;
	// public static String baseMicroRem;
	// // public static String genesNCBI;
	public static Color COLOR_CNV_0 = new Color(255, 0, 0);
	public static Color COLOR_CNV_1 = new Color(255, 136, 245);
	public static Color COLOR_CNV_2 = new Color(255, 255, 255);
	public static Color COLOR_CNV_3 = new Color(103, 193, 244);
	public static Color COLOR_CNV_4 = new Color(0, 0, 255);
	public static Color COLOR_CNV_LCSH = new Color(96, 54, 138);
	public static Color COLOR_CNV_MOZ = new Color(51, 153, 153);

	public GraphCytog(Group grpGraphique, Alteration alteration, boolean isRegion) {
		this.alteration = alteration;
		this.grpGraphique = grpGraphique;
		// Composite c = new Composite(grpGraphique, SWT.NONE);
		// c.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true, 1,
		// 1));
		// c.setLayout(new GridLayout(1, false));
		confPanel = new ConfigurationPanel(grpGraphique, isRegion);

		Composite cButton = new Composite(grpGraphique, SWT.NONE);
		cButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
		cButton.setLayout(new GridLayout(2, true));

		btnZoomPlus = new Button(cButton, SWT.NONE);
		btnZoomPlus.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		btnZoomPlus.setText("+");
		btnZoomPlus.setToolTipText("Permet de voir une plus petite région chromosomique");
		btnZoomPlus.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		btnZoomPlus.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				frame.zoomInDomain(-1.0, -1.0);
				updateTaille();
			}
		});

		btnZoomMoins = new Button(cButton, SWT.NONE);
		btnZoomMoins.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
		btnZoomMoins.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		btnZoomMoins.setText("-");
		btnZoomMoins.setToolTipText("Permet de voir une plus grande région chromosomique");
		btnZoomMoins.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				frame.zoomOutDomain(-1.0, -1.0);
				updateTaille();
			}
		});

		btnValidation = new Button(cButton, SWT.NONE);
		btnValidation.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		btnValidation.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 2, 1));
		btnValidation.setText("Appliquer la configuration");
		btnValidation.setToolTipText("Met à jour le graphique en fonction des cases cochées");
		btnValidation.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				regionGraphique.updateData();
				updateTaille();
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub

			}
		});

		btnLegende = new Button(cButton, SWT.NONE);
		btnLegende.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		btnLegende.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		btnLegende.setText("Légende");
		btnLegende.setToolTipText("Légende de l'iconographie du graphique");
		btnLegende.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {

			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub

			}
		});

		btnCNPc = new Button(cButton, SWT.NONE);
		btnCNPc.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
		btnCNPc.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
		btnCNPc.setText("Liste CNPc");
		btnCNPc.setToolTipText("Liste polymorphismes issus de la base Visiopuce");
		btnCNPc.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {

			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub

			}
		});

		cGraph = new Composite(grpGraphique, SWT.EMBEDDED);
		cGraph.setLayout(new GridLayout(2, false));
		GridData gd_cGraph = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_cGraph.minimumWidth = 800;
		gd_cGraph.minimumHeight = 800;
		gd_cGraph.widthHint = 800;
		gd_cGraph.heightHint = 800;
		cGraph.setLayoutData(gd_cGraph);
		createGraph();

		// cGraph.setLayout(new GridLayout(1, false));
		cGraph.pack();
		// c.pack();
		cButton.pack();
		// cGraph.pack();
		grpGraphique.pack();
	}

	public void createGraph() {

		Long taille = alteration.getFinHg19() - alteration.getDebutHg19();
		zoomValue = calculeZoom(taille);

		long tailleChr = ReferentielServiceImpl.getInstance().getTailleChromosome(alteration.getChromosome());

		fin = Math.min(tailleChr, alteration.getFinHg19() + seuil);
		debut = Math.max(0, alteration.getDebutHg19() - seuil);

		// fin = tailleChr;
		// debut = 0;

		defaultLowerBoundX = Math.max(0, alteration.getDebutHg19() + taille / 2 - zoomValue / 2);
		defaultUpperBoundX = defaultLowerBoundX + zoomValue;

		regionGraphique = new RegionGraphique(this, confPanel.getSelected(), alteration, debut, fin, seuil);

		jFreeChart = regionGraphique.creationGraphs();

		minBoundY = 0;
		maxBoundY = Math.max(1, regionGraphique.getTitreLignes().size()) + 1;

		frame = new MyChartPanel(this, cGraph, SWT.NONE, jFreeChart, 600, 600, 600, 600, 600, 600, true, false, true, true, true, false);
		// Composite comp, int style, JFreeChart jfreechart, int width, int
		// height, int minimumDrawW, int minimumDrawH, int maximumDrawW, int
		// maximumDrawH, boolean usingBuffer, boolean properties, boolean save,
		// boolean print, boolean zoom, boolean tooltips

		GridData gridData1 = new GridData(SWT.FILL, SWT.FILL, true, true);
		gridData1.widthHint = 700;
		gridData1.heightHint = 750;
		gridData1.minimumWidth = 700;
		gridData1.minimumHeight = 750;

		frame.setLayoutData(gridData1);

		frame.setDefaultLowerBoundX(defaultLowerBoundX);
		frame.setDefaultUpperBoundX(defaultUpperBoundX);
		frame.setMinBoundX(debut);
		frame.setMaxBoundX(fin);
		frame.setMinBoundY(minBoundY);
		frame.setMaxBoundY(maxBoundY);
		frame.restoreAutoDomainBounds();
		// frame.setInitialDelay(1);
		// frame.setReshowDelay(2);
		// frame.setDismissDelay(3);
		frame.setRangeZoomable(false);

		// // frame.setPopupMenu(new GraphPopupMenu(cp));
		frame.addChartMouseListener(this);
		// frame.addMouseWheelListener(new MouseWheelListener() {
		//
		// @Override
		// public void mouseScrolled(MouseEvent e) {
		// e.getSource();
		// // int rotation = e.getWheelRotation();
		// // setValue(getValue() + (getBlockIncrement(rotation) *
		// // rotation));
		// // vScrollBar.axisUpdate();
		// }
		// });
		vScrollBar = new ChartScrollBar(SWT.VERTICAL, cGraph, SWT.NONE | SWT.V_SCROLL, jFreeChart, frame);
		GridData gd_cGraph = new GridData(SWT.LEFT, SWT.LEFT, true, false, 1, 1);
		gd_cGraph.minimumWidth = 15;
		gd_cGraph.minimumHeight = 750;
		gd_cGraph.widthHint = 15;
		gd_cGraph.heightHint = 750;
		vScrollBar.getSlider().setLayoutData(gd_cGraph);

		// vScrollBar.getSlider().addListener(SWT.Selection, new Listener() {
		// public void handleEvent(Event event) {
		// String outString = "Event: SWT.NONE";
		// switch (event.detail) {
		// case SWT.ARROW_DOWN:
		// outString = "Event: SWT.ARROW_DOWN";
		// break;
		// case SWT.ARROW_UP:
		// outString = "Event: SWT.ARROW_UP";
		// break;
		// case SWT.DRAG:
		// outString = "Event: SWT.DRAG";
		// break;
		// case SWT.END:
		// outString = "Event: SWT.END";
		// break;
		// case SWT.HOME:
		// outString = "Event: SWT.HOME";
		// break;
		// case SWT.PAGE_DOWN:
		// outString = "Event: SWT.PAGE_DOWN";
		// break;
		// case SWT.PAGE_UP:
		// outString = "Event: SWT.PAGE_UP";
		// break;
		// }
		// }
		// });
		// vScrollBar.getSlider().addMouseWheelListener( new
		// MouseWheelListener() {
		//
		// @Override
		// public void mouseScrolled(MouseEvent e) {
		// e.getSource();
		// int rotation = e.getWheelRotation();
		// setValue(getValue() + (getBlockIncrement(rotation) * rotation));
		// }
		// });

		// frame.s
		hScrollBar = new ChartScrollBar(SWT.HORIZONTAL, cGraph, SWT.NONE | SWT.H_SCROLL, jFreeChart, frame);
		GridData gd_cGraphh = new GridData(SWT.LEFT, SWT.LEFT, true, false, 1, 1);
		gd_cGraphh.minimumWidth = 700;
		gd_cGraphh.minimumHeight = 15;
		gd_cGraphh.widthHint = 700;
		gd_cGraphh.heightHint = 15;
		hScrollBar.getSlider().setLayoutData(gd_cGraphh);
		int a = (int) (defaultUpperBoundX - defaultLowerBoundX / (fin - debut));
		hScrollBar.getSlider().setValues((int) (alteration.getDebutHg19() + ((alteration.getFinHg19() - alteration.getDebutHg19()) / 2)), (int) debut, (int) fin, a, a * 10, a);

		// frame = SWT_AWT.ne(w_Frame(cGraph);
		// frame.setMinimumSize(new Dimension(800, 1000));
		// frame.setAutoRequestFocus(true);

		// cp = new MyChartPanel(jFreeChart, false, true, true, true, false);
		// cp.setDefaultLowerBoundX(defaultLowerBoundX);
		// cp.setDefaultUpperBoundX(defaultUpperBoundX);
		// cp.setMinBoundX(debut);
		// cp.setMaxBoundX(fin);
		// cp.setMinBoundY(minBoundY);
		// cp.setMaxBoundY(maxBoundY);
		// cp.restoreAutoDomainBounds();
		// cp.setInitialDelay(1);
		// cp.setReshowDelay(2);
		// cp.setDismissDelay(3);
		// cp.setRangeZoomable(false);
		//
		// cp.setPopupMenu(new GraphPopupMenu(cp));
		// cp.addChartMouseListener(this);
		//
		// hScrollBar = new ChartScrollBar(ChartScrollBar.HORIZONTAL,
		// jFreeChart, cp);
		//
		// vScrollBar = new ChartScrollBar(ChartScrollBar.VERTICAL, jFreeChart,
		// cp);
		// vScrollBar.setUnitIncrement(10);
		//
		// cp.addMouseWheelListener(vScrollBar);

		// overviewChart = regionGraphique.creationOverviewGraph();
		// ChartComposite frame2 = new ChartComposite(grpGraphique, SWT.NONE,
		// overviewChart, true);
		//
		// GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true,
		// 2, 1);
		// gridData.widthHint = 800; // contrainte à 100px de large
		// gridData.heightHint = 100; // contrainte à 100px de haut
		// frame2.setLayoutData(gridData);

		// overviewPanel = new ChartPanel(overviewChart, 800, 70, 800, 70, 800,
		// 70, false, false, false, false, false, false);
		// Panel p2 = new Panel(new java.awt.FlowLayout());
		// p2.add(overviewPanel);
		//
		// p = new Panel(new BorderLayout());
		// p.add(cp, BorderLayout.CENTER);
		// p.add(vScrollBar, BorderLayout.EAST);
		// p.add(hScrollBar, BorderLayout.SOUTH);
		//
		// frame.add(p2, BorderLayout.NORTH);
		// frame.add(p, BorderLayout.CENTER);

		// frame.setSize(800, 1000);
		frame.pack();
		// frame2.pack();
		// regionGraphique.updateData();
		updateTaille();
		// tooltipframe = new Shell(frame.getShell(), SWT.ON_TOP | SWT.TOOL);
		// tooltipframe.setLayout(new FillLayout());
		// tool = new Label(tooltipframe, SWT.NONE);
		// tool.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
		// tool.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));

	}

	// public void init() {
	// codeBase = getCodeBase();
	// chromosome = getParameter("chromosome");
	//
	// idPuce = Integer.parseInt(getParameter("idPuce"));
	// idUtilisateur = Integer.parseInt(getParameter("idUtilisateur"));
	// region = Integer.parseInt(getParameter("region"));
	// estPatient = Integer.parseInt(getParameter("estPatient"));
	// groupe = getParameter("groupe");
	//
	// bandes = getParameter("bandes");
	// cnvChevauchants = getParameter("cnvChevauchants");
	// famille = getParameter("famille");
	// autrePucePatient = getParameter("autrePucePatient");
	//
	// fragile = getParameter("fragile");
	// imprinting = getParameter("imprinting");
	// microrem = getParameter("microrem");
	// baseMicroRem = getParameter("baseMicroRem");
	// redon = getParameter("redon");
	// cnpc = getParameter("cnpc");
	// clone32k = getParameter("clone32k");
	// clone4k = getParameter("clone4k");
	// cnpLyonGain = getParameter("cnpLyonGain");
	// cnpLyonPerte = getParameter("cnpLyonPerte");
	// cnpLyonTriplication = getParameter("cnpLyonTriplication");
	// cnpOuestGain = getParameter("cnpOuestDup");
	// cnpOuestPerte = getParameter("cnpOuestDel");
	// cnpOuestTriplication = getParameter("cnpOuestTriplication");
	// clonetilepath = getParameter("clonetilepath");
	//
	// confPanel.add(bp, BorderLayout.NORTH);
	//
	// confPanel.add(validationButton, BorderLayout.SOUTH);
	// regionGraphique = new RegionGraphique(this, confPanel, chromosome, debut,
	// fin, debutAlt, finAlt, idPuce, 10000);
	//
	// }

	// public void stop() {
	// tooltipframe.removeAll();
	// }

	// public void paint(Graphics g) {
	// super.paint(g);
	// updateTaille();
	// cp.repaint();
	// regionGraphique.repaint();
	// repaint();
	// }

	// public void update(Graphics g) {
	// paint(g);
	//
	// }

	public ChartScrollBar gethScrollBar() {
		return hScrollBar;
	}

	public ChartScrollBar getvScrollBar() {
		return vScrollBar;
	}

	public Composite getcGraph() {
		return cGraph;
	}

	public void setcGraph(Composite cGraph) {
		this.cGraph = cGraph;
	}

	void updateTaille() {
		int nbLignes = regionGraphique.getTitreLignes().size() + 4;

		if (hScrollBar != null) {
			int taille = (int) (regionGraphique.getChromosomePlot().getDomainAxis().getUpperBound() - regionGraphique.getChromosomePlot().getDomainAxis().getLowerBound());
			hScrollBar.getSlider().setValues((int) regionGraphique.getChromosomePlot().getDomainAxis().getLowerBound() + taille, (int) debut, (int) fin, Math.max(1, taille / 100), Math.max(1, taille / 10), Math.max(1, taille / 100));
		}
		if (vScrollBar != null) {
			vScrollBar.getSlider().setValues(0, 0, nbLignes, 1, 1, 14);
		}
	}

	// public void actionPerformed(ActionEvent e) {
	// if (e.getActionCommand().equals("Update_Data")) {
	// regionGraphique.updateData();
	// updateTaille();
	// } else if (e.getActionCommand().equals("zoomPlus")) {
	// cp.zoomInDomain(-1.0, -1.0);
	// } else if (e.getActionCommand().equals("zoomMoins")) {
	// cp.zoomOutDomain(-1.0, -1.0);
	// }
	// }

	// @Override
	// public void chartMouseMoved(ChartMouseEvent event) {
	// if (event.getEntity() instanceof XYItemEntity) {
	// frame.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_HAND));
	// if (((XYItemEntity) event.getEntity()).getDataset() instanceof
	// XYFloatingBarDataset) {
	// String tooltipText = event.getEntity().getToolTipText();
	// if (tooltipText != null && !tooltipText.equals(""))
	// tool.setText(tooltipText);
	// tooltipframe.pack();
	// if (!tooltipframe.isVisible()) {
	// tooltipframe.setLocation(event.getTrigger().getX(),
	// event.getTrigger().getY());
	// tooltipframe.setVisible(true);
	// // tool.addListener(SWT.MouseExit, labelListener);
	// // tool.addListener(SWT.MouseDown, labelListener);
	// Point size = tooltipframe.computeSize(SWT.DEFAULT, SWT.DEFAULT);
	// // Rectangle rect = item.getBounds(0);
	// // Point pt = table.toDisplay(rect.x, rect.y);
	// // tooltipframe.setBounds(pt.x, pt.y, size.x, size.y);
	// tooltipframe.setVisible(true);
	// }
	// // }
	// }
	// } else {
	// frame.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
	// tooltipframe.setVisible(false);
	// }
	// }

	// }
	// }
	// } else {
	// frame.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
	// tooltipframe.setVisible(false);
	// }
	// }

	public void chartMouseClicked(ChartMouseEvent event) {
		if (event.getEntity() instanceof XYItemEntity) {
			XYItemEntity e = ((XYItemEntity) event.getEntity());

			// tooltipframe.setVisible(false);
			// XYItemEntity e = ((XYItemEntity) event.getEntity());
			if (e.getDataset() instanceof XYFloatingBarDataset) {
				XYFloatingBarDataset fbds = ((XYFloatingBarDataset) e.getDataset());
				try {
					// URL ul = new URL(fbds.getLink(e.getSeriesIndex(),
					// e.getItem()));
					String url = fbds.getLink(e.getSeriesIndex(), e.getItem());
					if (!fbds.getLink(e.getSeriesIndex(), e.getItem()).contains("afficheCNV")) {
						if (url != null && !url.isEmpty() && url.contains("http:")) {
							PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(url));
						}
					} else {
						String[] tab = (fbds.getLink(e.getSeriesIndex(), e.getItem())).split("=");
						if (tab.length > 0) {
							int idAlt = Integer.parseInt(tab[1]);
							if (idAlt > 0) {
								Alteration a = AlterationServiceImpl.getInstance().getAlterationById(idAlt);
								int idPersonne = PersonneServiceImpl.getInstance().getIdPersonneFromObject(a);
								IEditorInput editorInput = new DossierEditorInput(idPersonne);
								PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, DossierEditor.ID, true, IWorkbenchPage.MATCH_INPUT);
								IEditorPart editeurActif = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
								if (editeurActif instanceof DossierEditor) {
									DossierEditor editeur = (DossierEditor) editeurActif;
									if (editeur.getCNVTabItems().containsKey(a.getPuce().getIdPuce())) {
										editeur.getTabFolder().setSelection(editeur.getCNVTabItems().get(a.getPuce().getIdPuce()).getTabItem());
									} else {
										editeur.addCNVTabItem(a);

									}
								}
							}

						}
					}
					// } catch (MalformedURLException e1) {
					// // TODO Auto-generated catch block
					// e1.printStackTrace();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (PartInitException e2) {
					e2.printStackTrace();
				}
			}
		}

	}

	public int calculeZoom(double taille) {
		int zoom;
		if (taille < 1000) {
			zoom = 1000;
		} else if (taille < 2500) {
			zoom = 2500;
		} else if (taille < 5000) {
			zoom = 5000;
		} else if (taille < 7500) {
			zoom = 7500;
		} else if (taille < 10000) {
			zoom = 10000;
		} else if (taille < 25000) {
			zoom = 25000;
		} else if (taille < 50000) {
			zoom = 50000;
		} else if (taille < 75000) {
			zoom = 75000;
		} else if (taille < 100000) {
			zoom = 100000;
		} else if (taille < 250000) {
			zoom = 250000;
		} else if (taille < 500000) {
			zoom = 500000;
		} else if (taille < 750000) {
			zoom = 750000;
		} else if (taille < 1000000) {
			zoom = 1000000;
		} else if (taille < 2500000) {
			zoom = 2500000;
		} else if (taille < 5000000) {
			zoom = 5000000;
		} else if (taille < 7500000) {
			zoom = 7500000;
		} else if (taille < 10000000) {
			zoom = 10000000;
		} else if (taille < 25000000) {
			zoom = 25000000;
		} else if (taille < 50000000) {
			zoom = 50000000;
		} else {
			zoom = 100000000;
		}
		return zoom;

	}

	public Alteration getAlteration() {
		return alteration;
	}

	public void setAlteration(Alteration alteration) {
		this.alteration = alteration;
	}

	public void repaint() {
		cGraph.redraw();
		// frame.redraw();
	}

	@Override
	public void chartMouseMoved(ChartMouseEvent event) {
		if (event.getEntity() instanceof XYItemEntity) {
			if (((XYItemEntity) event.getEntity()).getDataset() instanceof XYFloatingBarDataset) {
				if (ttd == null || ttd.getShell() == null) {
					frame.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_HAND));
					String tooltipText = event.getEntity().getToolTipText();
					if (tooltipText != null && !tooltipText.equals("")) {
						ttd = new ToolTipsDialog(frame.getShell(), tooltipText);
						ttd.open();
					}
				} else {
					if (!event.getEntity().getToolTipText().toUpperCase().equals(ttd.getText().toUpperCase())) {
						frame.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
						if (ttd != null && ttd.getShell() != null) {
							ttd.close();
						}
						frame.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_HAND));
						String tooltipText = event.getEntity().getToolTipText();
						if (tooltipText != null && !tooltipText.equals("")) {
							ttd = new ToolTipsDialog(frame.getShell(), tooltipText);
							ttd.open();
						}
					}
				}
			}
		} else {
			frame.getShell().setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
			if (ttd != null && ttd.getShell() != null) {
				ttd.close();
			}
		}
		//
		// if (ttd != null && ttd.getShell() != null) {
		// if (((XYItemEntity) event.getEntity()).getDataset() instanceof
		// XYFloatingBarDataset &&
		// !event.getEntity().getToolTipText().equals(ttd.getText())) {
		// frame.getShell().setCursor(new Cursor(Display.getCurrent(),
		// SWT.CURSOR_ARROW));
		// ttd.close();
		// }
		// } else {
		// if (((XYItemEntity) event.getEntity()).getDataset() instanceof
		// XYFloatingBarDataset) {
		// frame.getShell().setCursor(new Cursor(Display.getCurrent(),
		// SWT.CURSOR_HAND));
		// String tooltipText = event.getEntity().getToolTipText();
		// if (tooltipText != null && !tooltipText.equals("")) {
		// ttd = new ToolTipsDialog(frame.getShell(), tooltipText);
		// ttd.open();
		// }
		// // tool.setText(tooltipText);
		// // tooltipframe.pack();
		// // if (!tooltipframe.isVisible()) {
		// // tooltipframe.setLocation(event.getTrigger().getX(),
		// // event.getTrigger().getY());
		// // tooltipframe.setVisible(true);
		// // // tool.addListener(SWT.MouseExit, labelListener);
		// // // tool.addListener(SWT.MouseDown, labelListener);
		// // // Point size = tooltipframe.computeSize(SWT.DEFAULT,
		// // SWT.DEFAULT);
		// // // Rectangle rect = item.getBounds(0);
		// // // Point pt = table.toDisplay(rect.x, rect.y);
		// // // tooltipframe.setBounds(pt.x, pt.y, size.x, size.y);
		// // tooltipframe.setVisible(true);
		// // }
		// // // }
		// // } else {
		// //
		// // tooltipframe.setVisible(false);
		// // }
		// }
		// }
	}
	// }
	// }
	// } else {
	// frame.setCursor(new Cursor(Display.getCurrent(), SWT.CURSOR_ARROW));
	// tooltipframe.setVisible(false);
	// }

}
